package utils;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;

/**
 * @author 徐松辉
 * @date 2017年2月16日
 */
public class ReturnMsg {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	private Map<String, Object> returnMsgMap = new HashMap<>();

	public static ReturnMsg getReturnMsg() {
		return new ReturnMsg();
	}

	public static ReturnMsg getReturnMsg(Object obj) {
		ReturnMsg returnMsg = new ReturnMsg();
		return returnMsg.putObj(obj);
	}

	public ReturnMsg putMsg(String msg) {
		returnMsgMap.put("msg", msg);
		return this;
	}

	public ReturnMsg putObj(Object obj) {
		returnMsgMap.put("obj", obj);
		return this;
	}

	public ReturnMsg putOtherMsg(String key, String msg) {
		returnMsgMap.put(key, msg);
		return this;
	}

	public Map<String, Object> buildSuccess() {
		returnMsgMap.put("state", "0");
		logger.info("logId # {},returnData={}","当前返回结果没有logID",JSON.toJSONString(returnMsgMap));
		return returnMsgMap;
	}

	public Map<String, Object> buildError() {
		returnMsgMap.put("state", "1");
		logger.info("logId # {},returnData={}","当前返回结果没有logID",JSON.toJSONString(returnMsgMap));
		return returnMsgMap;
	}
	public Map<String, Object> buildSuccess(String logId) {
		returnMsgMap.put("state", "0");
		logger.info("logId # {},returnData={}",logId,JSON.toJSONString(returnMsgMap));
		return returnMsgMap;
	}

	public Map<String, Object> buildError(String logId) {
		returnMsgMap.put("state", "1");
		logger.error("logId # {},returnData={}",logId,JSON.toJSONString(returnMsgMap));
		return returnMsgMap;
	}
}
